package com.hzdesk.media.koreabatchmatvector.custom;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import com.hzdesk.media.koreabatchmatvector.R;


/**
 * Created by Administrator on 2018/7/12.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class MyFlyBorderView extends View {
    private float width_scale ;
    private float heigh_scale;
    public MyFlyBorderView(Context context) {
        super(context);
    }

    public MyFlyBorderView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyFlyBorderView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.my_fly_border_view);
        width_scale = typedArray.getFloat(R.styleable.my_fly_border_view_width_scale,1.05f);
        heigh_scale =  typedArray.getFloat(R.styleable.my_fly_border_view_heigh_scale,1.05f);
        typedArray.recycle();
    }
    /**
     *
     * @param newFocus 下一个选中项视图
     * @param  widthscale 选中项视图的伸缩大小
     */
    public void attachToView(View newFocus, float widthscale,float heighscale){
        int  widthInc = (int) (newFocus.getWidth() * widthscale);
        int heightInc = (int) (newFocus.getHeight() * heighscale);
        setFlyBorderLayoutParams(widthInc,heightInc);
    }
    public void hiddenToView(){
        setFlyBorderLayoutParams(0,0);
    }
    private void setFlyBorderLayoutParams(int width, int height){//设置焦点移动飞框的宽度和高度
        ViewGroup.LayoutParams params=getLayoutParams();
        params.width=width;
        params.height=height;
        setLayoutParams(params);
    }
}
